#include "qg_dlgrectangle.h"
#include "ui_qg_dlgrectangle.h"
#include "rs_vector.h"

QG_DlgRectangle::QG_DlgRectangle(QWidget *parent, bool modal, Qt::WindowFlags fl) :
    QDialog(parent, fl), offset(nullptr),
    Ui::qg_dlgrectangle()
{
    setModal(modal);
    setupUi(this);
    init();
}

QG_DlgRectangle::~QG_DlgRectangle() {
    destroy();
}

void QG_DlgRectangle::languageChange() {
    retranslateUi(this);
}

void QG_DlgRectangle::updateOffset() {
    int x = Ui_qg_dlgrectangle::width->value();
    int y =  Ui_qg_dlgrectangle::height->value();
    if (!x || !y || !offset) {
        return;
    }
    offset->x = x;
    offset->y = y;
}

void QG_DlgRectangle::init() {
    // nothing
}

void QG_DlgRectangle::setOffset(RS_Vector *offset) {
    this->offset = offset;
    if (!offset) {
        return;
    }
    Ui_qg_dlgrectangle::width->setValue(offset->x);
    Ui_qg_dlgrectangle::height->setValue(offset->y);
}
